import { fileURLToPath, URL } from 'node:url'
import AutoImport from 'unplugin-auto-import/vite'
import { defineConfig } from 'vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import vue from '@vitejs/plugin-vue'
// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      imports: ['vue'],
      resolvers: [ElementPlusResolver()],
      dts: true // 生成类型声明文件
    }),
    Components({
      resolvers: [
        // Element Plus 按需导入
        ElementPlusResolver(),
      ],
      dts: true, // 生成 components.d.ts 声明文件
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  server: {
    port: 5177, // 主应用端口
    cors: true, // 允许跨域
    origin: 'http://localhost:5177'
  },
  // 构建配置
  build: {
    target: 'esnext',
    minify: 'esbuild',
    cssCodeSplit: false
  }
})
